<template>
  <div>
    <template>
      <Card style="width:850px;margin: auto;">
        <Form :model="formLeft" label-position="left" :rules="validateLibForm" :label-width="100" style="width: 300px;margin: auto;">

          <FormItem label="路线代码:" prop="code">
            <Input v-model="formLeft.code" :maxlength="10"></Input>
          </FormItem>

            <FormItem label="描述:"  prop="description">
              <Input v-model="formLeft.description" :maxlength="100" type="textarea" style="width: 200px"/>
            </FormItem>

          <row type="flex" justify="center">
            <i-col span="20">

            </i-col>
            <i-col span="30">
              <Button type="primary"  @click="RoutingInsert">添加</Button>
              <Button type="success" style="margin-left: 160px" @click="back">返回</Button>
            </i-col>
          </row>

        </Form>
      </Card>
    </template>
  </div>
</template>

<script>
    import {RoutingInsert} from "../../../api/data"

    export default {
        data() {
            return {
                formLeft: {
                  code: '',
                  description:''
                },
              validateLibForm: {
                code: [
                  {required: true, message: '请输入', trigger: 'blur'}
                ],
                description: [
                  {required: true, message: '请输入', trigger: 'blur'}
                ],
              }
            }
        },
        mounted() {

        },
        methods: {
          RoutingInsert() {
                if (this.formLeft.code !== null && this.formLeft.code !== "") {
                  if (this.formLeft.description !== null && this.formLeft.description !== ""){
                    RoutingInsert(this.formLeft).then(res => {
                      this.$Message.success("添加成功");
                      this.$router.go(-1)
                    })
                  }else {
                    this.$Message.error("描述不能为空");
                  }
                } else {
                    this.$Message.error("路线代码不能为空");
                }
            },
            back() {
                this.$router.go(-1);
            },

        }
    }
</script>


